<script charset="utf-8" src="<?=base_url()?>resource/plugins/kindeditor/kindeditor.js"></script>
<script charset="utf-8" src="<?=base_url()?>resource/plugins/kindeditor/lang/<?=MYLANG=='sc'?'zh_CN':'en'; ?>.js"></script>
<script type="text/javascript" src="<?=base_url()?>resource/plugins/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript">
//表单验证
function product_submit() {
    /*----------------公共修改-------------------*/
    if(!isempty('maintain_id','维修单不能为空'))return false;
    //产品类别
    var sortId = $("#sortId").val();
    if(!sortId || sortId==''){
        alert('请选择产品类别');
        return false;
    }
    //数量
    if($("input[name=product_quantity]").val() <= 0){
        alert('产品数量必须大于0');
        return false;
    }
    /*----------------根据不同类型非空验证---------------------*/
    if(sortId==1 || sortId==2){
        //品牌
        if($("#brandId").val() == ''){
            alert('请选择产品品牌');
            return false;
        }
        if($("#brandId").val() == 37 && $("input[name=other_brand_name]").val() == ''){
            alert('请输入其他品牌名称');
            return false;
        }

        if(!isempty('product_model','品牌型号不能为空'))return false;
        if('<?=$isApple?>'==true && 2==1){
            var model = $('input[name=product_model]').val().toLowerCase();
            if(model!='iphone5' && model!='iphone5s' && model!='iphone6'){
                alert('型号必须是iphone5或iphone5s|iphone6');
                return false;
            }
            if(!$('input[name=iphone_ys]:checked').val()){
                alert('请选择iphone颜色');
                return false;
            }
            if(!$('input[name=iphone_nc]:checked').val()){
                alert('请选择iphone内存大小');
                return false;
            }
            if(!isempty('sku','sku不能为空,入库打印需要'))return false;
        }
        if(!isempty('imei','imei不能为空'))return false;
    }else if(sortId==3){
        if(!isempty('size','产品尺寸不能为空'))return false;
        if(!isempty('color','产品颜色不能为空'))return false;
        //是否支持蓝牙
        var is_bluetooth = $("input[name='is_bluetooth']:checked").val();
        if(!is_bluetooth){
            alert('请选择是否支持蓝牙');
            return false;
        }
        //是否支持遥控
        var is_yaokong = $("input[name='is_yaokong']:checked").val();
        if(!is_yaokong){
            alert('请选择是否支持遥控');
            return false;
        }
    }
	return true;
}

//产品类别
function productSort(sort_id){
    if(sort_id==1 && '<?=$isApple?>'==true){
        $('#brandId option[value=73]').prop('selected',true);
        $('#brandId option').not(':selected').prop('disabled',true);
        $('#iphoneColor').show();
    }else{
        $('#iphoneColor').hide();
        $('#brandId option').prop('disabled',false);
    }

    $('.form-group label.red').hide();
    $('.sort_params'+sort_id).show();
    $('.sort_params0').show();
}


//其他品牌
function otherBrand(brand_id){
    if(brand_id && brand_id == 37){
        $("#otherBrandId").show();
    }else{
        $("#otherBrandId").hide();
    }
}

//修改的时候默认选中
$(function(){
    var product_sortId = $("#sortId").val();
    if(product_sortId){
        $('.forms_left span').hide();
        $('.sort_params'+product_sortId).show();
        $('.sort_params0').show();
    }

    $('input[name=iphone_xh]').click(function(){
        $('input[name=iphone_nc]:checked').prop('checked',false);
        $('input[name=product_model]').val($(this).val());
    })

    $('input[name=iphone_ys]').click(function(){
        $('input[name=iphone_nc]:checked').prop('checked',false);
        $('input[name=color]').val($(this).val());
    })

    $('input[name=iphone_nc]').click(function(){
        $('input[name=size]').val($(this).val());
        //create sku
        var model = $('input[name=iphone_xh]:checked').val();
        var color = $('input[name=iphone_ys]:checked').val();
        var memory = $(this).val();
        console.log(model+'---'+color+'----'+memory);
        if(model=='iphone5'){
            if(color==2){
                if(memory==1){
                    $('input[name=sku]').val('sku49983');
                }else if(memory==2){
                    $('input[name=sku]').val('sku62935');
                }
            }else if(color==3){
                if(memory==1){
                    $('input[name=sku]').val('sku49982');
                }else if(memory==2){
                    $('input[name=sku]').val('sku62936');
                }
            }
        }else if(model=='iphone5s'){
            if(color==2){
                if(memory==1){
                    $('input[name=sku]').val('sku49954');
                }else if(memory==2){
                    $('input[name=sku]').val('sku49957');
                }
            }else if(color==3){
                if(memory==1){
                    $('input[name=sku]').val('sku49953');
                }else if(memory==2){
                    $('input[name=sku]').val('sku49956');
                }
            }else if(color==1){
                if(memory==1){
                    $('input[name=sku]').val('sku49955');
                }else if(memory==2){
                    $('input[name=sku]').val('sku49958');
                }
            }
        }else if(model=='iphone6'){
            if(color==2){
                if(memory==1){
                    $('input[name=sku]').val('sku56297');
                }else if(memory==2){
                    //$('input[name=sku]').val('sku62935');
                }
            }else if(color==3){
                if(memory==1){
                    $('input[name=sku]').val('sku59861');
                }else if(memory==2){
                    //$('input[name=sku]').val('sku62936');
                }
            }
        }
    })
})

KindEditor.ready(function(K) {
    window.editor = K.create('textarea',{
        resizeType : 1,
        allowPreviewEmoticons : false,
        allowImageUpload : true,
        width : '100%;',
        Height : '250px',
        langType : '<?=MYLANG=='sc'?'zh_CN':'en'; ?>',
        items : [
            'forecolor', 'hilitecolor','formatblock','bold','|', 'image', 'link']
    });
});

</script>

<!--菜单 start-->
<?php $this->load->view('defaults/common/left');?>
<!--菜单 end-->
<div id="content">
    <div class="page-header">
        <div class="container-fluid">
        <h1><?=lang('menu_ddgl')?></h1>
        <?=$this->breadcrumb->generateHTML();?>
        </div>
    </div>
    <div class="container-fluid">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title"><i class="fa fa-pencil"></i><?=lang('product_tjcp')?></h3>
            </div>
            <div class="panel-body">
                <div class="table-responsive">
                    <form class="form-horizontal" action="<?=blang_url('products/product/'.$post_type)?>" method="post" name="productForm" onsubmit="return product_submit()" autocomplete="off" style="overflow: hidden;">
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><?=lang('order_wxdh')?></label>
                            <div class="col-sm-10">
                                <span style="color: #008CD7;font-size: 16px;"><?=$productFirst['maintain_id']?></span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><label class="red sort_params0">*</label><?=lang('product_cptype')?></label>
                            <div class="col-sm-10">
                              <select class="form-control"  name="sort_id" id="sortId" onchange="productSort(this.value)">
                                    <option value="" >--<?=lang('public_qxz')?>--</option>
                                    <?php foreach ($sortList as $rs):?>
                                        <option value="<?=$rs['id']?>" <?=$optSort[$rs['id']]?> >
                                            <?=$rs['sort_name']?>
                                        </option>
                                    <?php endforeach;?>
                                </select>
                            </div>
                        </div>
                       <div class="form-group">
                            <label class="col-sm-2 control-label"><label class="red sort_params0">*</label><?=lang('product_wlsl')?></label>
                            <div class="col-sm-10">
                              <input class="form-control"  type="text" name="product_quantity" value="<?=$productFirst['product_quantity']?$productFirst['product_quantity']:1?>" onkeyup="value=value.replace(/[^\d]/g,'')" />
                              <label style="color:#1e91cf;">default value (1)</label>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><label class="red sort_params1 sort_params2">*</label><?=lang('product_sspp')?></label>
                            <div class="col-sm-10">
                              <select class="form-control" name="brand_id" id="brandId" onchange="otherBrand(this.value)">
                                    <option value="" >--<?=lang('public_qxz')?>--</option>
                                    <?php foreach ($brandList as $rs):?>
                                        <option value="<?=$rs['brand_id']?>" <?=$optBrand[$rs['brand_id']]?> >
                                            <?=$rs['brand_name']?>
                                        </option>
                                    <?php endforeach;?>
                                </select>
                                <span id="otherBrandId" style="display: none;">
                                      <?=lang('product_qtpp')?>：
                                      <input type="text" name="other_brand_name" value="<?=$productFirst['other_brand_name']?>" placeholder="请输入品牌名称" />
                                  </span><br>

                                  <span id="iphoneColor" style="display: none;">
                                    型号:
                                    <input type="radio" name="iphone_xh" value="iphone5"  />iphone5
                                    <input type="radio" name="iphone_xh" value="iphone5s"  />iphone5s
                                    <input type="radio" name="iphone_xh" value="iphone6"  />iphone6
                                    &nbsp;&nbsp;&nbsp;颜色:
                                    <input type="radio" name="iphone_ys" value="1"  />金
                                    <input type="radio" name="iphone_ys" value="2"  />银
                                    <input type="radio" name="iphone_ys" value="3"  />灰
                                    &nbsp;&nbsp;&nbsp;内存:
                                    <input type="radio" name="iphone_nc" value="1"  />16G
                                    <input type="radio" name="iphone_nc" value="2"  />32G
                                    <input type="radio" name="iphone_nc" value="3"  />64G
                                    &nbsp;&nbsp;&nbsp;指纹:
                                    <input type="radio" name="iphone_zw" value="1"  />Yes
                                    <input type="radio" name="iphone_zw" value="2"  />No
                                </span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><label class="red sort_params1 sort_params2">*</label><?=lang('product_cpxh')?></label>
                            <div class="col-sm-10">
                              <input class="form-control" type="text" name="product_model" value="<?=$productFirst['product_model']?>" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">sku</label>
                            <div class="col-sm-10">
                              <input class="form-control" type="text" name="sku" value="<?=$productFirst['sku']?>" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><label class="red sort_params1">*</label>IMEI</label>
                            <div class="col-sm-10">
                              <input class="form-control" type="text" name="imei" value="<?=$productFirst['imei']?>" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><label class="red sort_params3">*</label>尺寸</label>
                            <div class="col-sm-10">
                              <input class="form-control" type="text" name="size" value="<?=$productFirst['size']?>" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><label class="red sort_params3">*</label>颜色</label>
                            <div class="col-sm-10">
                              <input class="form-control" type="text" name="color" value="<?=$productFirst['color']?>" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><label class="red sort_params3">*</label>是否支持蓝牙</label>
                            <div class="col-sm-10">
                              <label class="oms-radio">
                                   <input type="radio" name="is_bluetooth" value="0" <?=$ckdsfly[0]?> />No
                                </label>
                                <label class="oms-radio">
                                    <input type="radio" name="is_bluetooth" value="1" <?=$ckdsfly[1]?> />Yes
                                </label>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><label class="red sort_params3">*</label>是否支持遥控</label>
                            <div class="col-sm-10">
                              <label class="oms-radio">
                                   <input type="radio" name="is_yaokong" value="0"  <?=$ckdsfyk[0]?> />No
                                </label>
                                <label class="oms-radio">
                                    <input type="radio" name="is_yaokong" value="1" <?=$ckdsfyk[1]?> />Yes
                                </label>
                            </div>
                        </div>
                        <?php if($productFirst['remark_cn']):?>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><?=lang('product_kfbz')?></label>
                            <div class="col-sm-10">
                              <?=$productFirst['remark_cn']?>
                            </div>
                        </div>
                        <?php endif; ?>
                         <div class="form-group">
                            <label class="col-sm-2 control-label"><?=$productFirst['remark_cn']?lang('product_zjbz'):lang('product_kfbz');?></label>
                            <div class="col-sm-10">
                              <textarea class="form-control" class="editor_id" name="append_remark" ></textarea>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label"></label>
                            <div class="col-sm-10">
                                <input type="hidden" name="id" value="<?=$productFirst['product_id']?>" />
                                  <input type="hidden" name="maintain_id" value="<?=$productFirst['maintain_id']?>" />
                                <input class="btn btn-primary" style="padding:8px 30px;" type="submit" value="<?=lang('public_tj')?>" name="submits"/>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

</div>








